<?php
class Core_Data_Mappers_Trainingsession extends Core_Data_Mappers_Abstract {
	protected $_businessclass = "Core_Business_Trainingsession";
	protected $_modelclass = "Core_Data_Models_Trainingsession";
	protected $_map=array("Id"=>"id","Trainingid"=>"trainingid","Trainerid"=>"trainerid",
	"Startdate"=>"startdate","Enddate"=>"enddate","Seatavailable"=>"seatavailable","Created"=>"created",
	"Updated"=>"updated");
	
	public function find($id) {
		$row = $this->getDbTable()->fetchAll(array("id=?"=>$id));
		if(isset($o)) {
			$output = $this->map($row->current);
			return $output;
		}
		return null;
	}
	public function add($object) {
		if($object instanceof $this->_businessclass && !$this->exists($object)) {
			$data = $this->reversemap($object);
			unset($data['id']);
			$id = $this->getDbTable()->insert($data);
			$object->Id = $id;
		}
	}
	public function edit($object) {
		if($object instanceof $this->_businessclass && $this->exists($object)) {
			$data = $this->reversemap($object);
			unset($data['id']);
			$this->getDbTable()->update($data, array("id = ?"=>$object->Id));
		}
	}
	public function exists($object) {
		if($object instanceof $this->_businessclass && null!==$this->find($object->Id)) 
			return true;
		else 
			return false;
	}
	public function fetchAll($where=null,$count=10,$start=0) {
		$rows = $this->getDbTable()->fetchRow($where,null,$count,$start);
		if(isset($rows)&& count($rows)>0) {
			$collection = array();
			foreach ($rows as $item) {
				$collection[] = $this->map($item);
			}
			return $collection;
		}
		return null;
	}
}
?>